 /*
 * Copyright (C) 2017-2024 Alibaba Group Holding Limited
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __RES_ICORE_H__
#define __RES_ICORE_H__

#include <aos/aos.h>
#include "av/swresample/resample.h"

__BEGIN_DECLS__

typedef struct res_icore res_icore_t;

/**
 * @brief  init the icore resample
 * @return 0/-1
 */
int res_icore_init();

/**
 * @brief  new a resampler
 * @param  [in] irate    : input sample rate
 * @param  [in] orate    : output sample rate
 * @param  [in] channels : 1/2, mono/stereo, support mono now only
 * @param  [in] bits     : 16 only
 * @return NULL on error
 */
res_icore_t *res_icore_new(uint32_t irate, uint32_t orate, uint8_t channels, uint8_t bits);

/**
 * @brief  get the max out samples number per channel
 * @param  [in] irate
 * @param  [in] orate
 * @param  [in] nb_isamples : number of input samples available in one channel
 * @return -1 on error
 */
int res_icore_get_osamples_max(uint32_t irate, uint32_t orate, size_t nb_isamples);

/**
 * @brief  convert nb_samples from src to dst sample format
 * @param  [in] hdl
 * @param  [in] out
 * @param  [in] nb_osamples : amount of space available for output in samples per channel
 * @param  [in] in
 * @param  [in] nb_isamples : number of input samples available in one channel
 * @return number of samples output per channel, -1 on error
 */
int res_icore_convert(res_icore_t *hdl, void **out, size_t nb_osamples, const void **in, size_t nb_isamples);

/**
 * @brief  free the resample
 * @param  [in] hdl
 * @return 0/-1
 */
int res_icore_free(res_icore_t *hdl);

__END_DECLS__

#endif /* __RES_ICORE_H__ */

